package com.cdxy.controller;

import com.cdxy.aop.ForceLogin;
import com.cdxy.biz.process.IRechargeBizProcess;
import com.cdxy.model.dto.base.controller.BaseController;
import com.cdxy.model.dto.base.resp.ApiResponse;
import com.cdxy.model.dto.base.resp.BasePageResp;
import com.cdxy.model.dto.req.*;
import com.cdxy.model.dto.resp.CreateOrderResp;
import com.cdxy.model.dto.resp.OrderDetailResp;
import com.cdxy.model.dto.resp.OrderListResp;
import com.cdxy.model.dto.resp.SuccessStatusAckResp;
import com.cdxy.util.AxUidUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: tangy
 * @Date: 2020/4/7 16:31
 */
@Api(tags = "支付接口")
@RestController
@RequestMapping("/pay")
public class PayController extends BaseController {
    @Autowired
    private IRechargeBizProcess rechargeBizProcess;

    @Autowired
    private AxUidUtil axUidUtil;

    @PostMapping("/cancelOrder")
    @ApiOperation(value = "取消订单")
    @ForceLogin
    public ApiResponse cancelOrder(@Validated @RequestBody CancelOrderReq cancelOrderReq) {
        cancelOrderReq.setAxUid(axUidUtil.getAxUid());
        rechargeBizProcess.cancelOrder(cancelOrderReq);
        return successApiResponse();
    }

    @PostMapping("/continueOrder")
    @ApiOperation(value = "继续支付订单")
    @ForceLogin
    public ApiResponse<CreateOrderResp> continueOrder(@Validated @RequestBody ContinueOrderReq continueOrderReq) {
        continueOrderReq.setAxUid(axUidUtil.getAxUid());
        return successApiResponse(rechargeBizProcess.continueOrder(continueOrderReq));
    }

    @PostMapping("/createSceneOrder")
    @ApiOperation(value = "创建景点门票订单")
    @ForceLogin
    public ApiResponse<CreateOrderResp> createSceneOrder(@Validated @RequestBody SceneOrderReq sceneOrderReq) {
        sceneOrderReq.setAxUid(axUidUtil.getAxUid());
        return successApiResponse(rechargeBizProcess.createSceneOrder(sceneOrderReq));
    }

    @PostMapping("/createHotelOrder")
    @ApiOperation(value = "创建酒店订单")
    @ForceLogin
    public ApiResponse<CreateOrderResp> createHotelOrder(@Validated @RequestBody SceneOrderReq sceneOrderReq) {
        sceneOrderReq.setAxUid(axUidUtil.getAxUid());
        return successApiResponse(rechargeBizProcess.createHotelOrder(sceneOrderReq));
    }

    @GetMapping("/sceneSuccessAck")
    @ApiOperation(value = "查询景点是否支付成功")
    public ApiResponse<SuccessStatusAckResp> sceneSuccessAck(@Validated SceneSuccessAckReq successAckReq) {
        return successApiResponse(rechargeBizProcess.sceneSuccessAck(successAckReq));
    }

    @GetMapping("/hotelSuccessAck")
    @ApiOperation(value = "查询酒店是否支付成功")
    public ApiResponse<SuccessStatusAckResp> hotelSuccessAck(@Validated SceneSuccessAckReq successAckReq) {
        return successApiResponse(rechargeBizProcess.hotelSuccessAck(successAckReq));
    }

    @GetMapping("/orderList")
    @ApiOperation(value = "订单信息", notes = "type(1-景点 2-酒店)")
    @ForceLogin
    public ApiResponse<BasePageResp<OrderListResp>> orderList(@Validated OrderListReq orderListReq) {
        orderListReq.setAxUid(axUidUtil.getAxUid());
        return successApiResponse(rechargeBizProcess.orderList(orderListReq));
    }

    @GetMapping("/orderDetail")
    @ApiOperation(value = "订单详情", notes = "")
    @ForceLogin
    public ApiResponse<OrderDetailResp> orderDetail(@Validated OrderDetailReq orderDetailReq) {
        return successApiResponse(rechargeBizProcess.orderDetail(orderDetailReq));
    }
}
